package com.davidniu.lesson01;

//import com.mysql.jdbc.Connection;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class JdbcFirstDemo {
    public static void main(String[] args) throws Exception {
        Class.forName("com.mysql.jdbc.Driver");

        String url ="jdbc:mysql://localhost:3306/jdbcstudy?useUnicode=true&characterEncoding=utf8&useSSL=true";
        String username = "root";
        String password = "123456";
        Connection connection = DriverManager.getConnection(url, username, password);
        Statement statement = connection.createStatement();
        String sql = "select * from users";
        ResultSet resultSet = statement.executeQuery(sql);
        while (resultSet.next()) {
            System.out.println("id = "+resultSet.getObject("id"));
            System.out.println("Name = "+resultSet.getObject("NAME"));
            System.out.println("Password = "+resultSet.getObject("PASSWORD"));
            System.out.println("Email = "+resultSet.getObject("email"));
            System.out.println("Birthday = "+resultSet.getObject("birthday"));
            System.out.println("======================");
        }
        resultSet.close();
        statement.close();
        connection.close();
    }
}
